﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace BankRemoteSystem.DAL
{
    class UserAO
    {
        public SqlDataAdapter sqldtStudent;
        public DataSet dtStudent;
        Connection con;
        public UserAO()
        {
            con = new Connection();
        }
        public DataSet getAll()
        {
            sqldtStudent = new SqlDataAdapter();
            SqlCommandBuilder sqlcombSouthAngle = new SqlCommandBuilder(sqldtStudent);
            dtStudent = new DataSet();
            Connection cdb = new Connection();
            string sql = "select * from [User]";
            sqldtStudent.SelectCommand = new SqlCommand(sql, cdb.getConnection());
            sqldtStudent.Fill(dtStudent, "User");
            return dtStudent;

        }
        public void save()
        {
            sqldtStudent.Update(dtStudent, "User");
        }
        public int deleteUser(string id)
        {
            DAL.Connection cdb = new DAL.Connection();
            SqlCommand cmd = new SqlCommand("spDeletUser", cdb.getConnection());
            SqlParameter sqlpa = new SqlParameter();
            sqlpa.ParameterName = "@UserID";
            sqlpa.SqlDbType = SqlDbType.NVarChar;
            sqlpa.Value = id;
            cmd.Parameters.Add(sqlpa);
            cmd.CommandType = CommandType.StoredProcedure;
            return cmd.ExecuteNonQuery();

        }
        public SqlDataReader getUserbyIDandPass(string userName, string password)
        {
            string sql = "select * from [User] where userID = '" + userName + "' and password = '" + password + "'";
            SqlCommand cmd = new SqlCommand(sql, con.getConnection());
            return cmd.ExecuteReader();
        }
    }
}
